<?php

use Hyperf\Database\Schema\Schema;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Migrations\Migration;

class CreateUserSigninLogsTable extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('user_signin_logs', function (Blueprint $table) {
            $table->bigIncrements('id')->unsigned();
            $table->unsignedBigInteger('user_id')->comment('用户ID')->index();
            $table->integer('points_earned')->default(0)->comment('获得积分');
            $table->integer('continuous_days')->default(0)->comment('连续天数');
            $table->date('signin_date')->comment('签到日期')->index();
            $table->timestamp('created_at')->nullable();

            $table->unique(['user_id', 'signin_date']);

            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');

            $table->comment('用户签到日志表');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('user_signin_logs');
    }
}
